﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Text;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using IntexReport.DataSource;
namespace WPFExcelReport
{

    public class FLTICCGABEWData : BaseFunction
    {
        public bool flagstartmtr;
        public bool flagRegenerateLastMonthData;
        string InvDate;
        string LASTINVDATE;
        ArrayList ListGBInventory;
        ArrayList ListTris = new ArrayList();
        string fileGBDATINV = Path.Combine(PathHelper.ApplicationPath, @"Report\Financial\GBDATINV.xml");
        SetData setINV = new SetData();
        DataTable tbGBDATINV;
        List<GBMOVEMENT> ListMov;
        List<WGSummary> ListWGSummary;
        string TrisInclude = "";
        public int ThreadCount;
        private string OrderNum;
        DataTable tbMov;
        public FLTICCGABEWData()
            : base()
        {
           
        }
        public FLTICCGABEWData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public FLTICCGABEWData(OracleConnection _myConnection, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_myConnection, _proxy, userID)
        {
        }
        public DataSet GetMovement(DataRow dwProperty)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            DataTable tableLocal = null;
            string STARTDATE, ENDDATE,LO,TYPE;
            STARTDATE = dwProperty["STARTDATE"].ToString().Trim();
            ENDDATE = dwProperty["ENDDATE"].ToString().Trim();
            LO = dwProperty["LO"].ToString().Trim();
            TYPE = dwProperty["TYPE"].ToString().Trim();
            try
            {
               
                OracleCommand or1 = OracleDB.CreateCommand();
                #region===============ICC_WBMOV=======================

                or1.CommandText = "SELECT A.ICCGABDAT,DECODE(A.ICCWH,'01','FI',A.ICCWH) AS ICCWH,A.ICCGABTYPE,A.ICCGABPARTIE,A.ICCGABSPPART,A.ICCGABFBPART, "
                    + " A.ICCGABZWPART,A.ICCGABCODE,A.ICCGABNAME,A.ICCGABDES,A.ICCGABLO,A.ICCGABLB, "
                    + " A.ICCGABLBEHI,A.ICCGABART,A.ICCGABVAR,A.ICCGSGARNBEZ,A.ICCGSAGARNNR,A.ICCGABFARBE, "
                    + " A.ICCGSCBEZ,A.ICCGABAUFKRS,A.ICCGABAUFLFD,A.ICCGABAUFPOS,A.ICCGABKG/1000 AS ICCGABKG "
                    + " FROM ICC_GABEW A "  
                    + " WHERE A.ICCGABBUCHDAT>='"+STARTDATE+"' AND A.ICCGABBUCHDAT<='"+ENDDATE+"' "
                    + " AND (DECODE(A.ICCWH,'01','FI',A.ICCWH) LIKE '" + LO + "%') AND A.ICCGABTYPE LIKE '" + TYPE + "%' "
                     ;
                #endregion
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    tableLocal = setResult.Tables[0];
                    tableLocal.TableName = "ICC_GABEW";
                    byte[] b;
                    string value;
                    string ColumnName = "";
                    foreach (DataRow dwTemp in tableLocal.Rows)
                    {
                        ColumnName = "ICCGSGARNBEZ";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                        ColumnName = "ICCGSCBEZ";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;
                        ColumnName = "ICCGABNAME";
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dwTemp[ColumnName] = value;                        
                    }
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
                
        public DataSet GetData(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                EventDispatcher.Instance.RaiseStatus("查询开始", StatusEventType.StartProgress);
                setINV.Clear();               
                EventDispatcher.Instance.RaiseStatus("装载出入库记录", StatusEventType.RunningProgress);
                setResult = GetMovement(dwUI);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("查询完成", StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                Tracer.Error(ABPOS + ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}